Repository navigation
fix(server/grants): persist the password grant's user identity so refresh works with sessions - #5168
Merged
nabokihms merged 3 commits intoNov 17, 2026
Conversation
…resh works with sessions A UserIdentity row was only ever written by the browser flow's finalize step, so a refresh token issued by the password grant — or minted before sessions were enabled — had none. With sessions on, every refresh of such a token failed GetUserIdentity and returned a 500. The password grant now creates/updates the identity the same way finalize.go does, and the refresh grant answers a missing identity with 400 invalid_grant instead of a 500: under sessions there are no cached claims to fall back to, so the token can no longer be honored. Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>
nabokihms
requested changes
Nov 16, 2026
nabokihms
left a comment
Member
There was a problem hiding this comment.
Thanks, the fix and the invalid_grant change look right. One thing inline that needs fixing before merge.
…ogin paths The password grant persisted the user identity the way finalizeLogin does but not the lock check ahead of it, so a locked account could still mint tokens. Both steps now live in one helper, useridentity.RecordLogin, called from the password grant and from finalizeLogin so the paths cannot drift apart again. A locked account gets access_denied from the token endpoint. Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>
…password grant Matches the response shape proposed in dexidp#5176: a locked account's token request is an invalid_grant (400), not access_denied. Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
With sessions enabled, every refresh of a token issued by the
passwordgrant fails with HTTP 500 ({"error":"invalid_request"}) and the server logsfailed to get user identity. The same happens for any refresh token minted before sessions were turned on.What this PR does / why we need it
Closes #5166
Only the browser flow writes a
UserIdentity(server/authflow/finalize.go), so a password-grant user never has a row, andserver/grants/refresh.goturns the resultingstorage.ErrNotFoundinto a 500.Two changes, along the lines the issue itself suggests:
finalize.godoes — created on first login, claims and last-login refreshed on later ones — so its refresh tokens resolve the cached claims under sessions, without contacting the upstream connector (the behaviourTestRefreshDisconnectsUpstreamWhenSessionsEnabledpins).400 invalid_grant, not a 500. Under sessions there are no cached claims to refresh against, so a token minted before sessions were enabled (or before this change) simply cannot be honored — a grant failure the client can act on, not a server fault.Verification — the new
TestRefreshGrantPasswordFlowWithSessionsissues a password-grant token with sessions enabled and refreshes it:master(a4755513):level=ERROR msg="failed to get user identity" err="not found"→expected: 200, actual: 500, body{"error":"invalid_request"}TestRefreshDisconnectsUpstreamWhenSessionsEnabled(refresh does not contact upstream under sessions),TestRefreshGrantStorageBackedPasswordDB(sessions off — the connector is still consulted), and the rest ofgo test ./server/...all pass;golangci-lint runreports 0 issues.Special notes for your reviewer
One existing assertion changed, deliberately:
TestRefreshTokenAuthTime's "sessions enabled but user identity missing" case asserted exactly the 500 #5166 reports. It now asserts400/invalid_grant, matching the issue's own suggestion. If you would rather see a different error, or a connector fallback here, I'm happy to adjust — I left the fallback out on purpose since the sessions design is that refresh must not contact the upstream.Deliberately out of scope: the grant mirrors
finalize.go's identity write, but not theBlockedUntillock checkfinalizeLoginruns on browser logins (the password grant never had an identity row to check). Worth a follow-up if you want the lock enforced on this path too.